package com.zbkj.admin.controller.brand;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.AgentCategorySaveRequest;
import com.zbkj.common.request.AgentCategorySearchRequest;
import com.zbkj.common.request.CommonBatchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.response.AgentCategoryDetailResponse;
import com.zbkj.common.response.AgentCategoryPageDataResponse;
import com.zbkj.common.response.BrandAgentCategoryPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.AgentCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌商代理分类管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/agent/category")
@Api(tags = "品牌商代理分类管理") //配合swagger使用

public class BrandAgentCategoryController {

    @Autowired
    private AgentCategoryService agentCategoryService;


    /**
     * 分页显示代理分类表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author Caiyc
     * @since 2025-07-25
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<BrandAgentCategoryPageDataResponse>> getList(@Validated AgentCategorySearchRequest request,
                                                                           @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<BrandAgentCategoryPageDataResponse> agentCategoryCommonPage = CommonPage.restPage(agentCategoryService.getListBrand(request, pageParamRequest));
        return CommonResult.success(agentCategoryCommonPage);
    }

    /**
     * 新增代理分类表
     * @param agentCategorySaveRequest 新增参数
     * @author Caiyc
     * @since 2025-07-25
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated AgentCategorySaveRequest agentCategorySaveRequest) {
        if(agentCategoryService.create(agentCategorySaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 批量删除
     * @param request
     * @return
     * @author Caiyc
     * @since 2025-07-25
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (agentCategoryService.batchDeleteBrand(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 修改代理分类表
     * @param agentCategoryRequest 修改参数
     * @author Caiyc
     * @author Caiyc
     * @since 2025-07-25
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AgentCategorySaveRequest agentCategoryRequest) {
        if (agentCategoryService.update(agentCategoryRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询代理分类表详情
     * @param id Integer
     * @author Caiyc
     * @since 2025-07-25
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<AgentCategoryDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(agentCategoryService.getDetailsBrand(id));
    }

}



